/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.stockkeeper.component;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.letmeshare.stockkeeper.sale.entities.Bill;
import org.letmeshare.stockkeeper.sale.entities.BillEntry;

/**
 *
 * @author Aby
 */
public class SaleTableModel extends DefaultTableModel{

private String[] cols=new String []  {
                "Id", "Date", "Total", "Paid"
            };

  

    public SaleTableModel(List<Bill> bills) {
         if(bills==null){
          setEmpty();
        }else{
            popupModel(bills);
        }
    }
    
    private void popupModel(List<Bill> bills){
        if(bills==null || bills.size()<1){
            setEmpty();
            return;
        }else{
            Object[][] data=new Object[bills.size()+1][5];
            for(int i=0;i<bills.size();i++){
                data[i]=new Object[]{bills.get(i).getId(),bills.get(i).getBilledOn(),bills.get(i).getTotalAmount(),bills.get(i).getPayableAmount()};
            }
            setDataVector(data, cols);
        }
    }

    private void setEmpty() {
         setDataVector( new Object [][] {
                {null, null, null, null}
            },
            cols);
    }
     @Override
    public boolean  isCellEditable(int row,int col){
        return false;
    }
    
}
